<template>
  <u-popup
    :show="showPopup"
    mode="center"
    round="5rpx"
    custom-style="height:300rpx;"
    @close="showPopup = false"
    close-on-click-overlay
  >
    <view class="p-10rpx">
      <u-image src="/static/images/other/nfc_cardReading.gif" mode="widthFix" width="200rpx" height="280rpx"> </u-image>
    </view>
  </u-popup>
</template>
<script setup>
import { ref } from "vue";
import { HnXfjNfcInit } from "./nfc-reader.js";


const showPopup = ref(false);

// 读卡
const reading = async () => {
  try {

    showPopup.value = true;
    //这里用异步获取读取到的NFC数据
    const { state, data } = await HnXfjNfcInit();
    console.log("reading>>> " +  { state, data } );

    //以下数据是我的业务逻辑代码，如果只要读取NFC数据上面那一行代码即可了。
    if (!data.CardNumb) {
      showPopup.value = false;
      return null;
    }
    showPopup.value = false;
    return data.CardNumb;
  } catch (error) {
    console.error(error);
    uni.showToast({
      title: error?.message + "",
      icon: "none",
    });
    showPopup.value = false;
  }
};

defineExpose({
  reading,
});
</script>
<style lang="scss"></style>
